package com.applications.codemash.core;

import com.applications.codemash.*;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Vibrator;
import android.widget.RemoteViews;

public class SessionNotificationAlarmReceiver extends BroadcastReceiver
{
	@Override
	public void onReceive(Context context, Intent intent)
	{
		NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
		Session session = (Session)intent.getExtras().get(Constants.SESSION_INTENT_KEY);
		RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.session_notification);
		
		contentView.setTextViewText(R.id.txtNotificationSession, session.getTitle());
		contentView.setTextViewText(R.id.txtNotificationSpeaker, session.getSpeakerName());
		contentView.setTextViewText(R.id.txtNotificationRoom, session.getRoom());
		contentView.setTextViewText(R.id.txtNotificationStart, session.getStartDisplay());
		contentView.setImageViewResource(R.id.imgNotificationIcon, R.drawable.codemash);
		
		Intent notificationIntent = new Intent(context, SessionInfo.class);
		notificationIntent.putExtra(Constants.SESSION_INTENT_KEY, session);
		PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
		
		Notification notification = new Notification(android.R.drawable.star_on, "CodeMash Session Starting",
				System.currentTimeMillis());
		notification.flags = Notification.FLAG_INSISTENT;
		((Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(300);
		notification.defaults = Notification.DEFAULT_SOUND;
		notification.contentView = contentView;
		notification.contentIntent = contentIntent;
		
		int notificationId = session.getNotificationId();
		manager.notify(notificationId, notification);
	}
}